<?php

/**
* alltosun.com 商品评论widget comment.php
* ============================================================================
* 版权所有 (C) 2009-2014 北京互动阳光科技有限公司，并保留所有权利。
* 网站地址: http://www.alltosun.com
* ----------------------------------------------------------------------------
* 许可声明: 这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
* ============================================================================
* $Author: 吴松键 (wusj@alltosun.com) $
* $Date: 2014-9-4 下午2:52:22 $
* $Id$
*/

class comment_widget
{
    private $per_page = 10;
    private $page_no  = 1;

    /**
     * 获取评论列表
     */
    public function get_list($params = array())
    {
        $this->page_no = Request::Get('page_no', 1);

        $is_empty = 0;
        if (isset($params['per_page']) && $params['per_page']) {
            $this->per_page = $params['per_page'];
        }
        if (isset($params['page_no']) && $params['page_no']) {
            $this->page_no = $params['page_no'];
        }
        if (isset($params['goods_id']) && $params['goods_id']) {
            $filter['id'] = comment_helper::get_comment_ids($params['goods_id']);
            if (empty($filter['id'])) {
                $is_empty = 1;
            }
        }
        $filter['status'] = 1;

        $list = array();
        if (!$is_empty) {
            $count = _model('comment')->getTotal($filter);
            if ($count) {
                $pager = new Pager($this->per_page);
                if ($pager->generate($count)) {
                    Response::assign('ajax_pager', $pager);
                    Response::assign('type', $params['goods_id']);
                }
                $list = _model('comment')->getList($filter, ' ORDER BY `add_time` DESC '.$pager->getLimit($this->page_no));
            }
            foreach ($list as $k=>$v) {
                $list[$k]['avatar']    = _uri('user', $v['user_id'], 'avatar');
                @$list[$k]['nick_name'] = user_helper::get_nick_name($v['user_id']);
            }
        }

        return $list;
    }
}
?>